
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __SKHYNIX_UART_H
#define __SKHYNIX_UART_H

/* Includes ------------------------------------------------------------------*/
#include "stm32f37x.h"

/* Exported constants --------------------------------------------------------*/
#define USE_UART1	// PC Interface
#define USE_UART2	// Input  : Zigbee
#define USE_UART3	// Output : VI2M

#ifdef	USE_UART1
#define UART1_CLK			RCC_APB2Periph_USART1
#define UART1_TX_CLK		RCC_AHBPeriph_GPIOC
#define UART1_TX_PORT		GPIOC
#define UART1_TX_SOURCE		GPIO_PinSource4
#define UART1_TX_AF			GPIO_AF_7
#define UART1_TX_PIN		GPIO_Pin_4
#define UART1_RX_CLK		RCC_AHBPeriph_GPIOC
#define UART1_RX_PORT		GPIOC
#define UART1_RX_SOURCE		GPIO_PinSource5
#define UART1_RX_AF			GPIO_AF_7
#define UART1_RX_PIN		GPIO_Pin_5
#endif	/* USE_UART1 */

#ifdef	USE_UART2
#define UART2_CLK			RCC_APB1Periph_USART2
#define UART2_TX_CLK		RCC_AHBPeriph_GPIOD
#define UART2_TX_PORT		GPIOD
#define UART2_TX_SOURCE		GPIO_PinSource5
#define UART2_TX_AF			GPIO_AF_7
#define UART2_TX_PIN		GPIO_Pin_5
#define UART2_RX_CLK		RCC_AHBPeriph_GPIOA
#define UART2_RX_PORT		GPIOA
#define UART2_RX_SOURCE		GPIO_PinSource3
#define UART2_RX_AF			GPIO_AF_7
#define UART2_RX_PIN		GPIO_Pin_3
#endif	/* USE_UART2 */

#ifdef	USE_UART3
#define UART3_CLK			RCC_APB1Periph_USART3
#define UART3_TX_CLK		RCC_AHBPeriph_GPIOB
#define UART3_TX_PORT		GPIOB
#define UART3_TX_SOURCE		GPIO_PinSource10
#define UART3_TX_AF			GPIO_AF_7
#define UART3_TX_PIN		GPIO_Pin_10
#define UART3_RX_CLK		RCC_AHBPeriph_GPIOE
#define UART3_RX_PORT		GPIOE
#define UART3_RX_SOURCE		GPIO_PinSource15
#define UART3_RX_AF			GPIO_AF_7
#define UART3_RX_PIN		GPIO_Pin_15
#endif	/* USE_UART3 */

#define	RING_BUF_SIZE		1024
#define	CHAR_CR				0x0D	//'\r'
#define	CHAR_LF				0x0A	//'\n'

/* Exported types ------------------------------------------------------------*/
typedef struct {
	u8	TxBuf[RING_BUF_SIZE];
	u32	TxHead;
	u32	TxTail;

	u8	RxBuf[RING_BUF_SIZE];
	u32	RxHead;
	u32	RxTail;
	u32	RxCRCnt;
} RING_BUF, *PRING_BUF;

typedef u32 (*fxPKTPARSING)(u8 *pPktBuf, u32 pktCnt);

/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void Uart_Init(fxPKTPARSING fxUart1Parsing, fxPKTPARSING fxUart2Parsing);
void Uart_Proc(u32 mode, u32 modeChanged);

void Uart3_Send(char *str);


#endif  /* __SKHYNIX_UART_H */
